#include<bits/stdc++.h>
#define int long long 
#define x first
#define y second
using namespace std;
const int N = 1e6+5;
int n,c,tot,a[N],b[N],cnt,pre[N],suf[N];
pair<int,int> p[N];
vector<pair<int,int>> vec;
int t[N];
#define lowbit(x) (x&(-x)) 
inline void add(int x,int v)
{
	for(;x<=cnt;x+=lowbit(x))
		t[x]+=v;
}
inline int ask(int x)
{
	int res = 0;
	for(;x;x-=lowbit(x)) res+=t[x];
	return res;
}
inline void change(int x,int y,int v){if(y<x)return;add(x,v),add(y+1,-v);}
int tmp[N],top;
inline void work()
{
	top = 0;
	int now = vec.size();
	for(auto _:vec) if(_.second!=-1) tmp[++top] = _.x-_.y+1;
	sort(tmp+1,tmp+top+1);
	pre[1]+=a[now]*now;
	int las = now;
//	cout<<(*vec.begin()).x<<':'<<now<<' '<<top<<'\n';
	tmp[top+1] = -1;
	for(int i = 1;i<=top;i++)
	{
		now--;
		if(tmp[i]!=tmp[i+1])
			pre[lower_bound(b+1,b+cnt+1,tmp[i])-b]+=a[now]*now-a[las]*las,las = now;
	}
	vec.clear();
}
int xxx;
inline int get(int x){return pre[x]+suf[x]+b[x]*c*xxx;}
signed main()
{
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i = 1,x,v;i<=n;i++)
	{
		cin>>x;
		if(x!=0) xxx++;
		int las = -1;
		while(x--)
		{
			cin>>v;
			if(las!=-1) b[++cnt] = v-las+1;
			p[++tot] = {v,las};
			las = v;
		}
	}
	sort(p+1,p+tot+1);
	p[tot+1] = {-1,-1};
	b[++cnt] = 1;
	sort(b+1,b+cnt+1),cnt = unique(b+1,b+cnt+1)-b-1;
//	for(int i = 1;i<=cnt;i++) cout<<b[i]<<" \n"[i==cnt];
	cin>>c;
	for(int i = 1;i<=n;i++) cin>>a[i];
//	cout<<"all "<<cnt<<'\n';
	for(int i = 1;i<=tot;i++)
	{
		if(p[i].y!=-1)
		{
			int lim = p[i].x-p[i].y+1;
			int x = lower_bound(b+1,b+cnt+1,lim)-b;
			//1~lim-1
			change(1,x-1,-1);
			suf[x-1]+=c;
//			if(x-1==1) cout<<"sb"<<suf[x-1]<<' '<<ask(x-1)<<' '<<suf[x-1]+ask(x-1)*(b[x]-b[x-1])*c<<'\n';
			suf[cnt]+=(lim-1)*c; 
		}
		vec.push_back(p[i]);
		if(p[i].x!=p[i+1].x) work();
	}
//	cout<<"s"<<suf[1]<<'\n';
	for(int i = 1;i<=cnt;i++) pre[i]+=pre[i-1];
	for(int i = cnt;i;i--)
	{
//		if(i<=46) cout<<"now"<<suf[i]<<'\n';
		suf[i]+=ask(i)*(b[i+1]-b[i])*c+suf[i+1];//,cout<<"x"<<i<<' '<<ask(i)<<'\n';
	}
//	cout<<"all "<<cnt<<'\n';
//	for(int i = 1;i<cnt;i++) if(suf[i]>suf[i+1]) cout<<"x"<<i<<":"<<ask(i)<<' '<<(b[i+1]-b[i])<<'\n';
	int mn = 2e18;
	for(int i = 1;i<=cnt;i++)
	{
		mn = min(mn,get(i));
//		if(b[i]==67||b[i]==34) cout<<i<<":"<<pre[i]<<' '<<suf[i]<<' '<<get(i)<<'\n';
	}
	cout<<mn<<' ';
	int ans = 0;
	for(int i = 1;i<=cnt;i++)
		if(get(i)==mn) ans++;
	cout<<ans<<'\n';
	for(int i = 1;i<=cnt;i++)
		if(get(i)==mn) cout<<b[i]<<' ';
	return 0;
}

